<?php
/*
// OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
// all the essential functionalities required for any enterprise.
// Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com

// OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
// the GNU General Public License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.

// OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along with this program;
// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA  02110-1301, USA
*/

require_once ROOT_PATH . '/lib/confs/Conf.php';
require_once ROOT_PATH . '/lib/dao/DMLFunctions.php';
require_once ROOT_PATH . '/lib/dao/SQLQBuilder.php';
require_once ROOT_PATH . '/lib/common/CommonFunctions.php';

class EmpAdminExam {

	var $tableName = 'HS_HR_EMP_ADMIN_EXAM';

	var $empId;
	var $empExamId;
	var $empComments;

	var $arrayDispList;
	var $singleField;

	function EmpAdminExam() {

	}

	function setEmpId($empId) {

		$this->empId=$empId;
	}

	function setEmpExamId($empExamId) {

		$this->empExamId=$empExamId;
	}

	function setEmpComments($empComments) {

		$this->empComments=$empComments;
	}

	function getEmpId() {

		return $this->empId;
	}

	function getempExamId() {

		return $this->empExamId;
	}

	function getEmpComments() {

		return $this->empComments;
	}

	function getListofEmpAdminExam($page,$str,$mode) {

		$tableName = 'HS_HR_EMP_ADMIN_EXAM';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->field = 'EMP_NUMBER';

		$sqlQString = $sql_builder->selectEmployee($page,$str,$mode);

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		while ($line = mysql_fetch_array($message2, MYSQL_NUM)) {

			$arrayDispList[$i][0] = $line[0];
			$arrayDispList[$i][1] = $line[1];
			$i++;

		}

		if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;

		}
	}

	function countEmpAdminExam($str,$mode) {

		$tableName = 'HS_HR_EMP_ADMIN_EXAM';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->field = 'EMP_NUMBER';

		$sqlQString = $sql_builder->countEmployee($str,$mode);

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$line = mysql_fetch_array($message2, MYSQL_NUM);

		return $line[0];
	}

	function delEmpAdminExam($arrList) {

		$tableName = 'HS_HR_EMP_ADMIN_EXAM';
		$arrFieldList[0] = 'EMP_NUMBER';
		$arrFieldList[1] = 'EXAM_ID';
		//print_r($arrList);exit;

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_delete = 'true';
		$sql_builder->arr_delete = $arrFieldList;

		$sqlQString = $sql_builder->deleteRecord($arrList);
		//echo $sqlQString;exit;

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

	}

	function delByAdminExam($arrList) {

		$tableName = 'HS_HR_EMP_ADMIN_EXAM';
		$arrFieldList[0] = 'EXAM_ID';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_delete = 'true';
		$sql_builder->arr_delete = $arrFieldList;

		$sqlQString = $sql_builder->deleteRecord($arrList);

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

	}

	function addEmpAdminExam() {

		$arrFieldList[0] = 'EMP_NUMBER';
		$arrFieldList[1] = 'EXAM_ID';
		$arrFieldList[2] = 'COMMENTS';

		$this->getEmpId();
		$arrRecordsList[0] = "'". $this->getEmpId()         . "'";
		$arrRecordsList[1] = "'". $this->getEmpExamId()  . "'";
		$arrRecordsList[2] = "'". $this->getEmpComments()   . "'";

		/* 记录技能加薪 by jingking start */
		/*require_once ROOT_PATH . '/lib/models/hrfunct/AdministraMana.php';
		$SalaryAdjArr['EmpId'] = $this->getEmpId();
		$SalaryAdjArr['MoldId'] = 2;
		$SalaryAdjArr['SalaryBefore'] = 0;
		$SalaryAdjArr['SalaryAfter'] = $this->getEmpExamSalary();
		$SalaryAdjArr['Content'] = "添加技能加薪";
		$AdministraMana = new AdministraMana();
		$AdministraMana->SaveSalaryAdjustments($SalaryAdjArr);*/
		/* 记录技能加薪 end */

		$tableName = 'HS_HR_EMP_ADMIN_EXAM';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_insert = 'true';
		$sql_builder->arr_insert = $arrRecordsList;
		$sql_builder->arr_insertfield = $arrFieldList;

		$sqlQString = $sql_builder->addNewRecordFeature2();

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		return $message2;
	}

	function updateEmpAdminExam() {

		$arrRecordsList[0] = "'". $this->getEmpId() . "'";
		$arrRecordsList[1] = "'". $this->getEmpExamId() . "'";
		$arrRecordsList[2] = "'". $this->getEmpComments() . "'";

		$tableName = 'HS_HR_EMP_ADMIN_EXAM';
		$arrFieldList[0] = 'EMP_NUMBER';
		$arrFieldList[1] = 'EXAM_ID';
		$arrFieldList[2] = 'COMMENTS';

		/* 记录技能加薪 by jingking start */
		/*require_once ROOT_PATH . '/lib/models/hrfunct/AdministraMana.php';
		if(isset($_POST['OldtxtExamSalary'])) {
		if($_POST['OldtxtExamSalary'] != $this->getEmpExamSalary()) {
		$SalaryAdjArr['EmpId'] = $this->getEmpId();
		$SalaryAdjArr['MoldId'] = 2;
		$SalaryAdjArr['SalaryBefore'] = $_POST['OldtxtExamSalary'];
		$SalaryAdjArr['SalaryAfter'] = $this->getEmpExamSalary();
		$SalaryAdjArr['Content'] = "修改技能加薪";
		$AdministraMana = new AdministraMana();
		$AdministraMana->SaveSalaryAdjustments($SalaryAdjArr);
		}
		}*/
		/* 记录技能加薪 end */

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_update = 'true';
		$sql_builder->arr_update = $arrFieldList;
		$sql_builder->arr_updateRecList = $arrRecordsList;

		$sqlQString = $sql_builder->addUpdateRecord1(1);
		//echo  $sqlQString;exit;
		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		return $message2;
	}


	function filterEmpAdminExam($getID) {

		$this->getID = $getID;
		$tableName = 'HS_HR_EMP_ADMIN_EXAM';
		$arrFieldList[0] = 'EMP_NUMBER';
		$arrFieldList[1] = 'EXAM_ID';
		$arrFieldList[2] = 'COMMENTS';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->arr_select = $arrFieldList;

		$sqlQString = $sql_builder->selectOneRecordFiltered($this->getID,1);
		//echo $sqlQString;exit;

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		while ($line = mysql_fetch_array($message2, MYSQL_NUM)) {

			for($c=0;count($arrFieldList)>$c;$c++)
			$arrayDispList[$i][$c] = $line[$c];

			$i++;

		}

		if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;
		}
	}

	function filterEmpAdminExam2($getID) {
		$empExamList = array();

		//$selecteFields[] = 'ea.`emp_number`';
		$selecteFields[] = 'a.`exam_id`';
		$selecteFields[] = 'a.`exam_salary`';
		$selecteFields[] = 'a.`exam_name`';

		$selectTables[] = '`hs_hr_emp_admin_exam` AS ea';
		$selectTables[] = '`hs_hr_admin_exam` AS a';

		$joinConditions[1] = 'ea.`exam_id` = a.`exam_id`';

		//$orderCondition = $selecteFields[1];
		$selectConditions[] = 'ea.`emp_number` ='.$getID;

		$sqlBuilder = new SQLQBuilder();
		$query = $sqlBuilder->selectFromMultipleTable($selecteFields, $selectTables, $joinConditions, $selectConditions, null, null);
		//echo $query;exit;

		//$query = preg_replace("/\\\'/", "'", $query);

		$dbConnection = new DMLFunctions();
		$result = $dbConnection->executeQuery($query);

		while($row = mysql_fetch_array($result, MYSQL_NUM)) {
			$empExamList[] = $row;
		}

		return $empExamList;
	}

	function getAssEmpAdminExam($getID) {

		$this->getID = $getID;

		$tableName = 'HS_HR_EMP_ADMIN_EXAM';
		$arrFieldList[0] = 'EMP_NUMBER';
		$arrFieldList[1] = 'EXAM_ID';
		$arrFieldList[2] = 'COMMENTS';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->arr_select = $arrFieldList;

		$sqlQString = $sql_builder->selectOneRecordFiltered($this->getID);

		//echo $sqlQString;
		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		while ($line = mysql_fetch_array($message2, MYSQL_NUM)) {

			for($c=0;count($arrFieldList)>$c;$c++)
			$arrayDispList[$i][$c] = $line[$c];

			$i++;
		}

		if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;
		}
	}

	function filterEmpAdmExamByEmp($emp_number) {
		$this->getID = $emp_number;
		$tableName = 'HS_HR_EMP_ADMIN_EXAM';
		$arrFieldList[0] = 'EMP_NUMBER';
		$arrFieldList[1] = 'EXAM_ID';
		$arrFieldList[2] = 'COMMENTS';

		$sql_builder = new SQLQBuilder();

		$sql_builder->table_name = $tableName;
		$sql_builder->flg_select = 'true';
		$sql_builder->arr_select = $arrFieldList;

		$sqlQString = $sql_builder->selectRecords($this->getID,'EMP_NUMBER');
		//echo $sqlQString;exit;

		$dbConnection = new DMLFunctions();
		$message2 = $dbConnection -> executeQuery($sqlQString); //Calling the addData() function

		$i=0;

		while ($line = mysql_fetch_array($message2, MYSQL_NUM)) {

			for($c=0;count($arrFieldList)>$c;$c++)
			$arrayDispList[$i][$c] = $line[$c];

			$i++;

		}

		if (isset($arrayDispList)) {

			return $arrayDispList;

		} else {

			$arrayDispList = '';
			return $arrayDispList;
		}
	}
	
	
	function getEmpAdmStr($empid) {
		$adminsql = "select b.exam_name, b.exam_salary from hs_hr_emp_admin_exam as a, hs_hr_admin_exam as b where a.emp_number='$empid' and a.exam_id=b.exam_id";
		$dbConnection = new DMLFunctions();
		$adminquery = $dbConnection->executeQuery($adminsql);
		$exam_sal = 0;
		$exam_remarks = '';
		while ($admexams = mysql_fetch_array($adminquery,MYSQL_ASSOC)) {
			$exam_sal += $admexams['exam_salary']?$admexams['exam_salary']:0;
			//$exam_remarks .= $admexams['exam_name']."(补助".$admexams['exam_salary']."),";
		}
		//$exam_remarks = rtrim($exam_remarks);
		return $exam_sal;
	}

}

?>
